/*
 * @Author: szx
 * @Date: 2021-12-05 14:48:52
 * @LastEditTime: 2022-02-23 13:15:50
 * @Description:
 * @FilePath: \leetcode\100-199\141\141.js
 */
function ListNode(val) {
    this.val = val;
    this.next = null;
}


var hasCycle = function (head) {
    if (!head || !head.next) return false;
    let slow =head;
    let fast = head.next;
    while (fast && fast.next) {
        fast = fast.next.next;
        slow = slow.next;
        if (fast == slow) return true;
    }
    return false;
};

/**
 * @param {ListNode} head
 * @return {boolean}
 */
var hasCycle = function (head) {
    if (!head || !head.next) return false;
    let slow = head;
    let fast = head.next;
    while (fast != slow) {
        if (!fast || !fast.next) return false;
        fast = fast.next.next;
        slow = slow.next;
    }
    return true;
};
